package com.yuanxin.app.appjob.controller.pc;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.yuanxin.app.appjob.appobject.WorkingDetailAO;
import com.yuanxin.app.appjob.common.MVCViewName;
import com.yuanxin.app.appjob.entity.gen.WorkingDetailCriteria;
import com.yuanxin.app.appjob.service.IWorkingDetail;
import com.yuanxin.framework.logging.Logger;
import com.yuanxin.framework.logging.LoggerFactory;
import com.yuanxin.framework.service.ServiceResult;
import com.yuanxin.framework.util.DateTimeUtils;

@Controller
@RequestMapping(value = "/pc/workingdetail")
public class WorkingDetailController {
	
	@Resource
	IWorkingDetail workingdetailService;
	
	private static Logger LOG = LoggerFactory.getLogger(WorkingDetailController.class);
	@RequestMapping(value = "", method = { RequestMethod.GET, RequestMethod.POST })
	
	 public ModelAndView getHello(Model model, HttpServletRequest request) {
        LOG.info("SessionId %s", request.getSession().getId());
        model.addAttribute("currentTime", DateTimeUtils.formateDateToStr(new Date(),DateTimeUtils.FORMAT_YMD_HMS));
 	
        ModelAndView mv = new ModelAndView();
        mv.addObject(model);
        
        return mv;
    }
	
	 @RequestMapping(value = "/list", method = { RequestMethod.GET, RequestMethod.POST })
	    public ModelAndView list(Model model, HttpServletRequest request) {
	        LOG.info("SessionId %s", request.getSession().getId());
	        model.addAttribute("currentTime", DateTimeUtils.formateDateToStr(new Date(),DateTimeUtils.FORMAT_YMD_HMS));
	 	
	        ModelAndView mv = new ModelAndView();
	        WorkingDetailCriteria cc = new WorkingDetailCriteria();
	        ServiceResult<List< WorkingDetailAO>> list =  workingdetailService.selectByCriteria(cc);
	        if(list!=null&& list.getData()!=null&& list.getData().size()>0){
	        	model.addAttribute("datalist", list.getData());
	        }else{
	        	model.addAttribute("datalist", new ArrayList());
	        }
	        mv.addObject(model);
	        mv.setViewName(MVCViewName.APP_APPJOB_PC_WORKINGDETAIL_WORKINGDETAILLIST.toString());
	        return mv;
	    }
	  
}